package org.example.fancystudy.CompletableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author chaigq
 * @version 1.0
 * @date 2022/11/8 14:15
 */
public class CompletableFutureFastDemo {
    public static void main(String[] args) {

        CompletableFuture completableFutureA = CompletableFuture.supplyAsync(() -> {
            System.out.println("completableFutureA Run");
            try {
                TimeUnit.SECONDS.sleep(3);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            return "completableFutureA";
        });

        CompletableFuture completableFutureB = CompletableFuture.supplyAsync(() ->{
            try {
                TimeUnit.SECONDS.sleep(5);
            }catch (Exception e){
                e.printStackTrace();
            }
            return "completableFutureB";
        });

        CompletableFuture completableFuture = completableFutureA.applyToEither(completableFutureB, f ->{
            return f + " win";
        });

        System.out.println(Thread.currentThread().getName() + completableFuture.join());
    }
}
